package com.bwie.controller;

import com.bwie.pojo.TgValue;
import com.bwie.pojo.User;
import com.bwie.service.impl.TgServiceImpl;
import com.bwie.service.impl.TgValueServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Time;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/tuangou")
@Slf4j
public class Controller {

    private static final Logger logger = LoggerFactory.getLogger(Controller.class);

    @Autowired
    TgServiceImpl tgService;
    @Autowired
    TgValueServiceImpl tgValueService;

    /**
     * 加入拼团
     * @param name
     * @return
     */
    @PostMapping("/add")
    public String Add(@Validated @RequestBody User name){
        TgValue tgValue = new TgValue();
        Date date = new Date();
        tgValue.setVTime(date);
        tgValue.setVName(name.getUsername());
        tgValue.setTId(name.getTgid());
        tgValueService.save(tgValue);
        List<TgValue> list = tgValueService.list();
        System.out.println(list.toString());
        return "拼团成功";
    }
}
